#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void fromIntToBinary(const float *number);
void toRight(unsigned int a, unsigned int b);
void toLeft(unsigned int a, unsigned int b);


int main(int argc, char *argv[]) {
	
	toLeft(12, 1);
	toRight(12, 1);
	
	return 0;
}

void fromIntToBinary(const float *number) {
	
	float copyNumber = *number;

	// buffer count for binary
	char buffer[80];
	size_t buffer_id = 0;

	// cicle for translate from numbers to binary
	while (copyNumber > 0) {
		
		// for integer
		if (floor(copyNumber) == copyNumber) {
			if (copyNumber != *number) {
				buffer[buffer_id] = '0';
			}
		// for float
		} else {
			copyNumber = (int)copyNumber;
			if (copyNumber != *number) {
				buffer[buffer_id] = '1';
			}
		}
		
		buffer_id++;
		copyNumber = copyNumber / 2;
	}

	// output binary numbers in reverse order
	for(size_t id = (buffer_id - 1); id > 0; id--) {
		printf("%c", buffer[id]);
	}
}

void toRight(unsigned int a, unsigned int b) {
	
	float aa = ((float)a);
	
	fromIntToBinary(&aa);
	unsigned int c = a >> b;
	float cc = ((float) c);
	
	printf("(%d) >> %d = ", a, b);
	fromIntToBinary(&cc);
	printf("(%d)\n", c);
	
}

void toLeft(unsigned int a, unsigned int b) {

	float aa = ((float)a);
	
	fromIntToBinary(&aa);
	unsigned int c = a << b;
	float cc = ((float) c);
	
	printf("(%d) << %d = ", a, b);
	fromIntToBinary(&cc);
	printf("(%d)\n", c);
	
}

/*
result:

1100(12) << 1 = 11000(24)
1100(12) >> 1 = 110(6)

*/
